package com.inspur.his.convert;


import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

//自定义的日期类型转换器的实现
public class CustomDateConverter implements Converter<String, Date> {
//原类型：String  目标类型：Date
    @Override
    public Date convert(String source) {
        SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");
        Date today = new Date();
        Date converDay = null;
        try{
            if(null == source || "".equals(source))
                converDay = simpleDateFormat.parse(simpleDateFormat.format(today));
            else
                converDay = simpleDateFormat.parse(source);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return converDay;
    }
}
